<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ include file="/commons/taglibs.jsp" %>
<html>
<head>
 <link href="../../../js/thickbox.css" rel="stylesheet" type="text/css" />
      <script src="../../../js/jquery-1.5.min.js" type="text/javascript"></script>
      <script src="../../../js/jqtool.js" type="text/javascript"></script>
      <script src="../../../js/ui.js" type="text/javascript"></script>
      <script src="../../../js/thickbox-compressed.js" type="text/javascript"></script>
		<script src="../../../js/jqui/jquery-1.2.6.min.js" type="text/javascript"></script>
 	   <link href="../../../css/Public.css"type="text/css" rel="stylesheet" />
       <link href="../../../css/PublicEdit.css"type="text/css" rel="stylesheet" /> 
       	<script language="javascript" src="../../../js/dateselect.js"></script>
<title>新增广告 </title>
<style>
.gonggao{
    position:absolute;
    top:80px;
    left:200px;
    width:430px;
    height:300px;
    border:1px solid #993300;
    background-color:#ffffff;
}
.gonggao h1{
    line-height:50px;
    font-size:24px;
    font-family:"黑体";
    font-weight:bold;
    text-align:center;
}
.gonggao div{
    line-height:30px;
    font-size:18px;
    font-family:"黑体";
    text-align:center;
    color:#993300;
}
.gonggao div a,.gonggao div a:visited{
    color:#993300;
}
</style>

<script type="text/javascript">
    function clsGG(srcpath)
    {
    	window.document.getElementById("viewimg").src= '${ctx}/showImage?imgfile='+srcpath;
    	//src;
    	//"E://Workspaces//MyEclipse9//ksappstore//WebRoot//upload//800X600//460.jpg";
        jQuery("#gonggao").toggle();        
    }
    function closediv()
    {
    document.all("gonggao").style.display="none";
    }
  
</script>
<script type="text/javascript">
			function checkData()
			{						
					//验证数据   新用户名称
					var uname= window.document.getElementById("adinfo_title").value;					
					var str="false";	
			        if(uname!=null && uname!="")
			        {		
			        	//限制 字符和数字、长度
			        	if(uname.length>30)
			        	{
			        	 	alert("广告名称过长，最长30位！");
			        	 	window.document.getElementById("adinfo_title").focus();
			           		window.event.returnValue = false;
			            	return;
			        	}	 			         		
			        }
			        else
			        {            
			            alert("请输入广告名称！");
			            window.document.getElementById("adinfo_title").focus();
			            window.event.returnValue = false;
			            return;
			        }	
			        var adinfo_url= window.document.getElementById("adinfo_url").value;	
			        if(adinfo_url!=null && adinfo_url!="")
			        {		
			        	//限制 字符和数字、长度
			        	if(adinfo_url.length>300)
			        	{
			        	 	alert("URL过长，最长300位！");
			        	 	window.document.getElementById("adinfo_url").focus();
			           		window.event.returnValue = false;
			            	return;
			        	}	
			        	 var strRegex = "^((https|http|ftp|rtsp|mms)://)?[a-z0-9A-Z]{3}\.[a-z0-9A-Z][a-z0-9A-Z]{0,61}?[a-z0-9A-Z]\.com|net|mobi|cn|cc|so (:s[0-9]{1-4})?/$";			  var re = new RegExp(strRegex);			  
						   var re =/^(https|http|ftp|rtsp|mms):\/\/[A-Za-z0-9]+\.[A-Za-z0-9]+[\/=\?%\-&_~`@[\]\':+!]*([^<>\"\"])*$/;
						   if(!re.test(adinfo_url)){
							     alert("URL不合法，请检查后重新输入");
							       document.getElementById("adinfo_url").focus();
							     window.event.returnValue = false;
			           			 return;							     
							 }  
							  $.ajaxSettings.async = false;
							  $.getJSON("/admin/json/isexsistAdUrl?url=" + adinfo_url+"&rnd="+Math.random(), function(data) {
						  	 if(data.str=='Y'){
						  		alert("该广告已经存在！");
						  		str="true";
						 	}
							}); 
							if(str=='true'){
							window.event.returnValue = false;
							return ;
							}  
			        }
			        else
			        {            
			            alert("请输入URL！");
			            window.event.returnValue = false;
			            return;
			        }
			        var adinfo_startdate= window.document.getElementById("adinfo_startdate").value;	
			        if(adinfo_startdate==null ||adinfo_startdate=="")
			        {	
			            alert("请选择开始日期！");
			            window.document.getElementById("adinfo_startdate").focus();
			            window.event.returnValue = false;
			            return;
			        }	
			        var adinfo_enddate= window.document.getElementById("adinfo_enddate").value;	
			        if(adinfo_enddate==null ||adinfo_enddate=="")
			        {	
			            alert("请选择结束日期！");
			            window.document.getElementById("adinfo_enddate").focus();
			            window.event.returnValue = false;
			            return;
			        }	
			         if(Date.parse(adinfo_startdate.replace("-","/")) > Date.parse(adinfo_enddate.replace("-","/")))
			         {
						  alert("开始时间大于结束时间，请检查!");
						  window.document.getElementById("adinfo_startdate").focus();
						   window.event.returnValue = false;
			           		return;
					 }										 
						  	        
			        
			        var adinfo_starttime= window.document.getElementById("adinfo_starttime").value;
			        if(adinfo_starttime!=null &&adinfo_starttime!="")
			        {				       							     
						if(!isInt(adinfo_starttime))  
			        	{
			        		alert("开始时间点必须在0-24之间！");
			        	 	window.document.getElementById("adinfo_starttime").focus();
			           	 	window.event.returnValue = false;
			            	return;
			        	} 	
			        	if (adinfo_starttime < 0 || adinfo_starttime > 24)
							{
							    alert("开始时间点必须在0-24之间！");	
							    window.document.getElementById("adinfo_starttime").focus();
							    window.event.returnValue = false;									
								return;
							} 		
			        }
			        else
			        {	
			            alert("请输入开始时间！");
			            window.document.getElementById("adinfo_starttime").focus();
			            window.event.returnValue = false;
			            return;
			        }	
			        
			        var adinfo_endtime= window.document.getElementById("adinfo_endtime").value;
			        if(adinfo_endtime!=null &&adinfo_endtime!="")
			        {				       							     
						if(!isInt(adinfo_endtime))  
			        	{
			        		alert("结束时间点必须在0-24之间！");
			        	 	window.document.getElementById("adinfo_endtime").focus();
			           	 	window.event.returnValue = false;
			            	return;
			        	} 	
			        	if(adinfo_endtime < 0 || adinfo_endtime > 24)
							{
							    alert("结束时间点必须在0-24之间！");	
							    window.document.getElementById("adinfo_endtime").focus();
							    window.event.returnValue = false;									
								return;
							} 		
			        }
			        else
			        {	
			            alert("请输入结束时间！");
			            window.document.getElementById("adinfo_endtime").focus();
			            window.event.returnValue = false;
			            return;
			        }		
								
					var chks=document.getElementsByTagName("input");
				     var len=chks.length;		   
				     for (i=0; i<len; i++) 
				     {
				        var cur=chks[i];
				        if(cur.type=="file")
				            {  				            
				            	var fv=cur.value;				           
				            	if(fv==null||fv=='')
				            	{
					            	//upimg="false";
					            	//break;		
					            	alert("请选择图片上传！");	
					       			window.document.getElementById(cur.id).focus();
								    window.event.returnValue = false;
								    return;				            	
				            	}
				            	else
				            	{
				            		var extname = fv.substring(fv.lastIndexOf(".")+1,fv.length);
									   extname = extname.toLowerCase();//处理了大小写
									    if(extname!= "bmp"&&extname!= "jpg"&&extname!= "gif"&&extname!="png")
									    {
									       alert("只能上传bmp,jpg,gif,png格式的图片！");
									       window.event.returnValue = false;
								   			 return;	
									    }						            		
				            	}
					        }       
				    }	
				  
			        var onenumber= window.document.getElementById("adinfo_orderid").value;					     
						if(!isInt(onenumber))  
			        	{
			        		alert("显示顺序必须是大于或等于0的整数！");
			        	 	window.document.getElementById("onenumber").focus();
			           	 	window.event.returnValue = false;
			            	return;
			        	} 	
			       bbform.submit();			        		      
			}	
			function isInt(str)
			{
				//var reg = /^(-|\+)?\d+$/ ;
				if(str==0)return true;
				var reg = /^[1-9]\d*$/;	
				return reg.test(str);			
			}		
			 function test(obj)
			 {
				  var str = document.getElementsByName("province");
			       if(obj.checked==true)
			       {
				       for(var i=0;i<str.length;i++)
				       {
				      	 document.getElementsByName("province")[i].checked = true;
				       }
			       }	       
			        if(obj.checked==false)
			        {
					       for(var i=0;i<str.length;i++)
					       {
					       		document.getElementsByName("province")[i].checked = false;
					       }
			       }	
			}		
 </script>		
</head>
<body >
<form action="SaveAd" name="bbform" id="bbform" method="post" enctype="multipart/form-data">
<div id="gonggao" class="gonggao" style="display:none">
     <img name="viewimg" id="viewimg" style="width:400;height:300" />	
      <a href="javascript:closediv();">关闭</a>     						 
</div>
				<div>
		                <div class="l_f_top">
		                    <div class="l_f_top_left_div"><img alt="" src="../../../images/tb.gif" width="16" height="16" /></div>
		                    <div class="l_f_top_right_div">新增广告        </div>
		                </div>
		                <div class="l_f_body"> 		                 
		                     <div class="l_f_body_row">
		                        <div class="l_f_body_div1">                            名称:</div>
		                        <div class="l_f_body_div5">
				                       <input type="text"  name ="adinfo.title" id="adinfo_title" style="width:150px"/>  
					           </div>                      
		                    </div>	 		                  
		                        <div class="l_f_body_row">
		                        <div class="l_f_body_div1">                            URL:</div>
		                        <div class="l_f_body_div5">
				                       <input type="text"  name ="adinfo.url" id="adinfo_url" style="width:150px"/>  
					           </div>                      
		                    </div>	
		                    <div class="l_f_body_row">
								<div class="l_f_body_div1">
									开始日期:
								</div>
								<div class="l_f_body_div5">
									<input type="text" onclick="show_calendar(this)" name="adinfo.startdate" id="adinfo_startdate" style="width:150px"/>									
								</div>
							</div>							
							<div class="l_f_body_row">
								<div class="l_f_body_div1">
									结束日期:
								</div>
								<div class="l_f_body_div5">
									<input type="text" onclick="show_calendar(this)" name="adinfo.enddate" id="adinfo_enddate" style="width:150px"/>									
								</div>
							</div>  
		                    <div class="l_f_body_row">
								<div class="l_f_body_div1">
									开始时间:
								</div>
								<div class="l_f_body_div5">
									<input type="text" name="adinfo.starttime" id="adinfo_starttime" style="width:120px" maxlength="2" value="0"/>
									点
								</div>
							</div>							
							<div class="l_f_body_row">
								<div class="l_f_body_div1">
									结束时间:
								</div>
								<div class="l_f_body_div5">
									<input type="text" name="adinfo.endtime" id="adinfo_endtime" style="width:120px" maxlength="2" value="24"/>
									点
								</div>
							</div>
							<div class="l_f_body_row">
								<div class="l_f_body_div1">
									&nbsp;省&nbsp;&nbsp;份:
								</div>
								<div class="l_f_body_div5">
								<input type="checkbox" name="checkall" id="checkall" onclick="test(this)" />全选<br/>
								<c:forEach items="${prolist}" var="pro" varStatus="status">
									<c:if test="${status.count%8==0}" >
										<input type="checkbox" name="province" id="province" value="${pro.PId}"/>${pro.provincename}<br/>
									</c:if>
								<c:if test="${status.count%8!=0}" >
								<input type="checkbox" name="province" id="province" value="${pro.PId}"/>${pro.provincename}
								</c:if>
								</c:forEach>					
								</div>
							</div>	
							${ResolutionList}
		                     <div class="l_f_body_row">
								<div class="l_f_body_div1">
									显示顺序:
								</div>
								<div class="l_f_body_div5">
									<input type="text" name="adinfo.orderid" id="adinfo_orderid" value="0"  style="width:120px" maxlength="2"/>
								</div>
							</div>
		                     <div class="l_f_body_row">
		                        <div class="l_f_body_div1">                              状态:</div>
		                        <div class="l_f_body_div5" >
		               		     <select name="adinfo.isshow" id="adinfo_isshow" style="width: 120px">
									<option value="0">
										关闭
									</option>								
									<option value="1" selected>
										开放
									</option>							
								</select>
							   </div>
							   </div>
		                     <div class="center l_f_body_foot">			                     
		                       <input type="button" id="button" name="button" class="button2_60" onclick="checkData();"  value="提交"/>		                      
		                      <input type="button" class="button2_60"  onclick="javascript:history.go(-1);" value=" 返回"/><!-- 
		                      <input type="button" class="button2_60"  onclick="clsGG('E://Workspaces//MyEclipse9//ksappstore//WebRoot//upload//800X600//460.jpg');" value="test"/>
		                      <input type="button" class="button2_60"  onclick="clsGG('F://阳朔旅游//DSC05564.JPG');" value="test"/>  
							--></div>
		                </div>
			    	</div> 
</form>
</body>
</html>